package demo.restful;


import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;

/**
 * Created by IntelliJ IDEA.
 * User: jinshengyuan
 * Date: 2019-02-22
 * Time: 13:30
 * description:
 **/
public class CategoryServiceClient {


    public static void main(String[] args) {
        //WebPageClientImpl client = new WebPageClientImpl()
        /*WebClient webClient = WebClient.create("http://localhost:9000/");
        Category category = webClient.path("categoryservice/category/001").accept("application/xml").get(Category.class);
        System.out.println("Category details from REST service.");
        System.out.println("Category Name " + category.getCategoryName());
        System.out.println("Category Id " + category.getCategoryId());
        System.out.println("Book details for Category " +category.getCategoryId() + " from REST service");
        String bookString = "categoryservice/category/" +  category.getCategoryId() + "/books";*/


        /*WebClient clientBook = WebClient.create("http://localhost:9000/");
        Category categoryBooks = clientBook.path(bookString).accept("application/xml").get(Category.class);
        Iterator<Book> iterator = categoryBooks.getBooks().iterator();
        while (iterator.hasNext()) {
            Book book = iterator.next();
            System.out.println("Book Name " + book.getBookName());
            System.out.println("Book ISBN " + book.getBookISBNnumber());
            System.out.println("Book ID " + book.getBookId());
            System.out.println("Book Author " + book.getAuthor());
        }*/

        CategoryService categoryService = new CategoryService();

        // Service instance
        JAXRSServerFactoryBean restServer = new JAXRSServerFactoryBean();
        restServer.setResourceClasses(Category.class,Book.class);
        //restServer.setServiceBeans((List<Object>) categoryService);
        //restServer.setServiceBeanObjects(categoryService);
        restServer.setServiceBean(categoryService);
        restServer.setAddress("http://localhost:9999/");
        restServer.create();

    }



}
